package homework;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class number3 {
public static void main(String[] args) throws Exception {
	 String sourceFolderPath = "F://008";
     String targetFolderPath = "bbb";
     File sourceFolder = new File(sourceFolderPath);
     File targetFolder = new File(targetFolderPath);
     copyAll(sourceFolder, targetFolder);
     System.out.println("文件夹拷贝完成！");
}
public static void copyAll(File srcFile,File destFile) throws Exception{
	if (srcFile.isDirectory()) {
        if (!destFile.exists()) {
            destFile.mkdir();
        }
	File[] listFiles = srcFile.listFiles();
	if(listFiles!=null){
		for (File file : listFiles) {
			if(file.isFile()){
				FileInputStream fis=new FileInputStream(file);
				FileOutputStream fos=new FileOutputStream(new File(destFile, file.getName()));
				byte [] buf=new byte[1024];
				int len=0;
				while((len=fis.read(buf))>0){
					fos.write(buf,0,len);
				}
				fis.close();
	            fos.close();
				
			}else{
				copyAll(file, new File(destFile, file.getName()));
			}
		}
	}
}
}
}


